package com.example.videooncarmera;

import sci.tool.ActivityComponent;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;


/** 获取屏幕点击处的坐标 */
public class passwordInput extends ActivityComponent
{
	private static boolean isShowing = false;
	
	/** 显示当前Activity */
	public static void Show(Activity context/*, String tipInfo*/)
	{
		if(isShowing) return;
		
		Intent intent = new Intent(context, passwordInput.class);
//		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//		intent.putExtra("tipInfo", tipInfo);
		
//		context.startActivity(intent);
		context.startActivityForResult(intent, CODE_InputBox);
	}
	
	// ----------------
	
	@Override
	public void Init(Bundle savedInstanceState)
	{
		this.setContentView("activity_password");
		isShowing = true;
		DelPassword();		// 清除密码输入显示
		
//		String tipInfo = this.getIntent().getStringExtra("tipInfo");
//		EditText("editText").setHint(tipInfo);
		
//		Click("buttonReset");
	}

	public static final int CODE_InputBox = 50001;
	
	
	private String Password = "";
	private void InputPassword(String C)
	{
		if(Password.length() < 6)
		{
			Password += C;
			SetPassword(Password);
		}
	}
	
	/** 删除一个密码字符 */
	private void DelPassword()
	{
		if(Password.length()>0) Password = Password.substring(0, Password.length()-1);
		SetPassword(Password);
	}
	
	/** 设置密码的显示 */
	private void SetPassword(String Password)
	{
		for(int i=1; i<=6; i++)
		{
			if(i <= Password.length())
			{
				TextView("text_pass" + i).setText("*");
			}
			else TextView("text_pass" + i).setText("");
		}
	}
	
	/** 设置返回的密码 */
	private void SetReturnPassword(String value)
	{
		Intent data = new Intent();
		data.putExtra("VALUE", value);
		this.setResult(CODE_InputBox, data);
		
		this.finish();
		isShowing = false;
	}
	
	@Override
	public void Click(String viewId)
	{
		if(viewId.startsWith("btn_num_back"))
		{
			DelPassword();
		}
		else if(viewId.startsWith("btn_num"))
		{
			String num = viewId.substring("btn_num".length());
			InputPassword(num);
		}
		
		if (viewId.equals("btn_Yes"))
		{
			SetReturnPassword(Password);
//			this.finish();
		}
		else if (viewId.equals("btn_Cancel"))
		{
			SetReturnPassword("");
//			this.finish();
		}
	}
	
	public void onBackPressed()
	{
//		Click("btn_Cancel");
	}
	
//	public boolean dispatchTouchEvent(MotionEvent event)
//	{
//		switch (event.getAction())
//		{
//			case MotionEvent.ACTION_DOWN:
//				setPosition((int) event.getX(), (int) event.getY());
//				break;
//			
//			case MotionEvent.ACTION_UP:
//				break;
//		}
//		return super.dispatchTouchEvent(event);
//		
//	}
//	
//	boolean isSet = false;
//	int x;
//	int y;
//	
//	public void setPosition(int x, int y)
//	{
//		if (!isSet)
//		{
//			isSet = true;
//			LinearLayout("linear1").setVisibility(View.VISIBLE);
//			LinearLayout("linear2").setVisibility(View.VISIBLE);
//			this.EditText("editText1").setText("" + x + ", " + y);
//		}
//	}
//	
}
